package com.googlecode.beanfiles.utils;

import java.util.Arrays;

import org.apache.commons.beanutils.Converter;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class ListConverter implements Converter {

    protected static Log log() {
        return LogFactory.getLog(ListConverter.class);
    }
    
    public ListConverter() { }
    
    /**
     * BeanUtils conversion to list.
     */
    @SuppressWarnings("unchecked")
    public Object convert(Class type, Object value) {
        if (value instanceof String) {
            return Arrays.asList(StringUtils.stripAll(((String)value).split(",")));
        } else if (type.isArray()) {
            return Arrays.asList((Object[])value);
        } else {
            return null;
        }
    }            
    
    
}
